package com.test;

import java.io.File;
import java.util.ArrayList;

public class test {
    public static void main(String[] args){
        //java获取12套背景图
        ArrayList<String> bacList = new ArrayList<>();
        File bacFile = new File("D:/图片素材/test/moban1");
        File[] bacFiles = bacFile.listFiles();
        for (int i = 0; i < bacFiles.length; i++) {
            File file1 = bacFiles[i];
            String fileName = file1.getName();
            String prefix = fileName.substring(fileName.lastIndexOf(".") + 1)
                    .toLowerCase();
            if ("jpg".equals(prefix) || "png".equals(prefix)
                    || "bmp".equals(prefix) || "gif".equals(prefix)) {
                bacList.add(fileName);
            }
        }

        //java获取ui图的所有图片
        File fileUi = new File("D:/图片素材/test/ui");
        File[] fileUis = fileUi.listFiles();
        ArrayList<String> uiList = new ArrayList();
        for (int i = 0; i < fileUis.length; i++) {
            File file1 = fileUis[i];
            String fileName = file1.getName();
            String prefix = fileName.substring(fileName.lastIndexOf(".") + 1)
                    .toLowerCase();
            if ("jpg".equals(prefix) || "png".equals(prefix)
                    || "bmp".equals(prefix) || "gif".equals(prefix)) {
                uiList.add(fileName);
            }
        }

        //java获取框架文件里所有图片
        ArrayList<String> list = new ArrayList();
        File file = new File("D:/图片素材/test/kuangjia/05 Chery");
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            File file1 = files[i];
            String fileName = file1.getName();
            String prefix = fileName.substring(fileName.lastIndexOf(".") + 1)
                    .toLowerCase();
            if ("jpg".equals(prefix) || "png".equals(prefix)
                    || "bmp".equals(prefix) || "gif".equals(prefix)) {
                list.add(fileName);
            }
        }
        for (String s1:
             list) {
            System.out.println(s1);
        }

        for (String s:
                list) {
            String[] splitStrings = s.split("_");
            String fileNameStr = splitStrings[0];
            String year = splitStrings[1];
            for (String s1:
                 bacList) {
                File file11 = new File("D:\\图片素材\\test\\result1\\05 Chery\\"+fileNameStr);
                if(!file11.exists()){
                    file11.mkdir();
                }
                String[] backStrings = s1.split("_");
                String backName = backStrings[0];
                int x1 = Integer.parseInt(backStrings[1]);
                int y1 = Integer.parseInt(backStrings[2]);
                int x2 = Integer.parseInt(backStrings[3]);
                int y2 = Integer.parseInt(backStrings[4]);


                try {
                    ImageUtils.margeImage(x1,y1,x2,y2,"D:\\图片素材\\test\\moban1\\"+s1,
                            "D:\\图片素材\\test\\kuangjia\\05 Chery\\"+s, "D:\\图片素材\\test\\ui\\2.jpg",
                            "D:\\图片素材\\test\\result1\\05 Chery\\"+fileNameStr+"\\"+backName+".png", fileNameStr, year);
                }catch (Exception e){
                    e.printStackTrace();
                }

            }
        }



    }
}
